Skip to content

Fix issue with newly created template under an existing one #19669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AndyButland
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Resolves: #19632

Description

The linked issue illustrates problems when creating a template under an existing one - the newly created template loses it's updates and appears to have changes when it doesn't.

The problem looks to occur when we attempt to load the newly created template and we don't get the data returned from the API, rather the originally scaffolded content.

Resetting the state before loading as I've done here does fix the problem - but it may be more something that illustrates the problem and a more competent front-end reviewer can find to do in a better way.

Testing

Create a template under and existing one, and verify the master template is correctly identified for subsequent editing.

@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 08:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue where editing a newly created template under an existing one would fall back to the scaffolded template instead of loading the fresh data. By resetting the workspace state before invoking the parent load method, the correct API data is fetched and applied.

  • Reset workspace state at the start of load to avoid short‐circuited returns.
  • Preserve correct master template linkage when creating a new template.

Copy link
Member

@nielslyngsoe nielslyngsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this for now, seems like another solution should be found. :-)

// Reset state before load to ensure we don't short-circuit the load method.
// Without this on editing a newly created template we won't get the created data,
// rather the initial scaffold.
super.resetState();
Copy link
Member

@nielslyngsoe nielslyngsoe Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem right, here a few notes from the investigation for who ever gets to look into this next.

The data scaffolded via the Creation flow does not seem to set the masterTemplate of the data.
Which results in the Master Template being gone when the line below (74):
this.setMasterTemplate(response.data.masterTemplate?.unique ?? null); gets executed.

This should not be resolved by loading the template from the server again, but instead, we should make sure the Master Template logic sets the masterTemplate in the 'current' data, so our data is correct.

Currently, we do not experience this data problem because the Master Template is being displayed from a UI state and not bound to the data of the template.

So instead we should update the data as part of this.setMasterTemplate.

Something like this:

this._data.updateCurrent({ masterTemplate: { unique: ... } });

I will as well add that we should consider if the whole State for Master Template could be omitted in favor of an Observable part for that specific part of the data. I have not had the time at hand to investigate this closer, but it seems that could make everything a lot simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a template under a template does not save properly
2 participants